//
//  DoctorChatTableViewCell.m
//  QuickCure1
//
//  Created by summer的Dad on 16/11/1.
//  Copyright © 2016年 maoge. All rights reserved.
//

#import "DoctorChatTableViewCell.h"
#import "MessageModel.h"
//
@interface DoctorChatTableViewCell()
@property (nonatomic, weak) UILabel *timeLabel;  //消息时间label
@property (nonatomic, weak) UIImageView *iconImageView;  //图像框
@property (nonatomic, weak) UIImageView *dialogImageView; //聊天消息背景
@property (nonatomic, weak) UILabel *messageLabel;     //消息类容

@end
@implementation DoctorChatTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
    
}
//重写set方法
- (void)setModel:(MessageModel *)model
{
    _model = model;
    self.timeLabel.text = model.time;
    self.messageLabel.text = model.text;
    
}
- (void)setupUI
{
    self.selectionStyle = NO;
    
    //消息发送时间的label
    UILabel *timeLabel = [[UILabel alloc] init];
    timeLabel.font = [UIFont systemFontOfSize:14];
    timeLabel.textColor = [UIColor colorWithWhite:0.8 alpha:1];
    
    [self.contentView addSubview:timeLabel];
    self.timeLabel = timeLabel;
    
    //图片框
    UIImageView *iconImageView = [[UIImageView alloc] init];
    
    [self.contentView addSubview:iconImageView];
    self.iconImageView = iconImageView;
    
    iconImageView.image = [UIImage imageNamed:@"illness_img_person.png"];
    
    
    //消息的背景框
    UIImageView *dialogImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:dialogImageView];
    self.dialogImageView = dialogImageView;
    
    
    //消息label框
    UILabel *messageLabel = [[UILabel alloc] init];
    messageLabel.numberOfLines = 0;
    [self.contentView addSubview:messageLabel];
    self.messageLabel = messageLabel;
    
    //timeLabel约束
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.centerX.equalTo(self.contentView);
    }];
    
    //iconImageView约束
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(8);
        make.top.equalTo(timeLabel.mas_bottom).offset(8);
        make.width.height.equalTo(@50);
    }];
    
    //背景框约束
    [dialogImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(iconImageView.mas_right).offset(8);
        make.top.equalTo(iconImageView);
    }];
    
    //消息内容约束
    [messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(dialogImageView).mas_offset(UIEdgeInsetsMake(8, 16, 8, 8));
        make.width.lessThanOrEqualTo(@200);
    }];
    
//    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.right.left.equalTo(self);
//        make.bottom.greaterThanOrEqualTo(iconImageView).offset(8);
//        make.bottom.greaterThanOrEqualTo(dialogImageView).offset(8);
//    }];
 
    
    
    
    
}
//选中单元格调用
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    //普通状态下的图片
    UIImage *image = [UIImage imageNamed:@"Dialog_white_press.left"];
    image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.8];
    
    //选中消息时的方法
    UIImage *pressImage = [UIImage imageNamed:@"Dialog_white_press.left"];
    pressImage = [pressImage stretchableImageWithLeftCapWidth:pressImage.size.width * 0.5 topCapHeight:pressImage.size.height * 0.8];
    
    self.dialogImageView.image = highlighted ? pressImage : image;
    
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
